<?php

require 'vendor/autoload.php';

use Pheanstalk\Pheanstalk;

$ph = Pheanstalk::create('127.0.0.1','11301');

echo 'consumer begin...';

$i = 0;

while (true){
    //监听通道
    try{
        $job = $ph->watch('goodLists')->reserve();

        $data = json_decode($job->getData(),true);

        echo 'job id:'.$job->getId();
        print_r($data);

        if ($data[0]['id'] == 0)
        {
            ++$i;
            if ($i == 1)
            {
                $ph->watch('goodLists')->touch($job);
                print_r($ph->statsJob($job));
            }
            else
            {
                $ph->delete($job);
            }

        }
        else
        {
            //删除任务，表示任务完成
            $ph->delete($job);
        }
    }
    catch (Exception $e)
    {
        print_r($e->getMessage());
    }


}

